<?php

namespace App\Admin\Controllers;

use App\AdminPermission;

class PermissionController extends Controller
{
    //权限列表页面
    public function index()
    {
        $permissions = AdminPermission::all();
        
        return view('admin/permission/index', compact('permissions'));
    }

    //权限创建页面
    public function create()
    {
        return view('admin/permission/add');
    }

    //权限保存
    public function store()
    {
        $this->validate(request(), [
            'name'  => 'required|min:3',
            'description'=>'required'
        ]);

        $name = request('name');
        $description = request('description');

        AdminPermission::create(compact('name', 'description'));

        return redirect('/admin/permissions');
    }
}
